package com.hb.trans.mvp.ui.activity


import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.basiclib.base.BaseActivity
import com.basiclib.utils.ImmersionBar
import com.flyco.tablayout.listener.CustomTabEntity
import com.hb.trans.R
import com.hb.trans.bean.TabEntity
import com.hb.trans.global.ACTIVITY_TRANS_INFO
import com.hb.trans.mvp.presenter.TransInfosPresenter
import com.hb.trans.mvp.ui.fragment.BaseInfoFragment
import com.hb.trans.mvp.ui.fragment.TransInfosFragment
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.activity_trans_info.*

@Route(path = ACTIVITY_TRANS_INFO)
class TransInfoActivity : BaseActivity() {

    override fun getContentViewResId(): Int = R.layout.activity_trans_info

    override fun onActivityInject() {
        AndroidInjection.inject(this)
    }

    override fun attachView(savedInstanceState: Bundle?) {
        ImmersionBar.with(this)
            .statusBarColor(R.color.colorPrimary)
            .init()
    }

    override fun getPresenter(): TransInfosPresenter? = null

    override fun initView() {
        setUpNavBar()
    }

    private fun setUpNavBar() {
        val titles = arrayOf("基本信息", "学时查询")
        val selectIcons = arrayOf(R.mipmap.ic_base_info_s, R.mipmap.ic_trans_time_s)
        val unSelectIcons =
            arrayOf(R.mipmap.ic_base_info_un, R.mipmap.ic_trans_time_un)
        val tabs = ArrayList<CustomTabEntity>(titles.size)
        for (i in 0 until titles.size) {
            tabs.add(TabEntity(titles[i], selectIcons[i], unSelectIcons[i]))
        }
        val fragments = ArrayList<androidx.fragment.app.Fragment>()
        fragments.add(BaseInfoFragment.newInstance())
        fragments.add(TransInfosFragment.newInstance())
        transInfoCtl.setTabData(tabs, this, R.id.flTransInfo, fragments)
    }

    override fun initData() {

    }

    override fun setListener() {
        transInfoToolbar.backClick()?.subscribe { finish() }
    }

    override fun onDestroy() {
        super.onDestroy()
        ImmersionBar.with(this).destroy()
    }
}
